var countdown = 60;
var mess_btn = $(".message_btn");
var code;

//点击切换登陆方式
$(".zhmalogin").click(function () {
    $(".zhmalogin").hide()
    $(".sjhlogin").show()

    $(".form1").hide()
    $(".form2").show()
})

$(".sjhlogin").click(function () {
    $(".sjhlogin").hide()
    $(".zhmalogin").show()

    $(".form2").hide()
    $(".form1").show()
})


$(".message_btn").click(function () {
    $.ajax({
        url: "shopmessage",
        type: "GET",
        data: {"phone": $("input[name='phone']").val()},
        dataType: "json",
        success: function (data) {
            if (data.flag) {
                code = data.code;
                Toast('获取成功', 2000);
            } else {
                Toast('获取失败', 2000);
            }
        },
    })
})

function settime(val) {
    if (countdown == 0) {
        val.removeAttribute("disabled");
        val.value = "获取验证码";
        countdown = 60;
    } else {
        val.setAttribute("disabled", true);
        val.value = "重新发送(" + countdown + ")";
        countdown--;
        setTimeout(function () {
            settime(val)
        }, 1000)
    }
}

function login() {
    if ($(".code").val() == code) {
        $.ajax({
            url: "shopphoneLogin",
            type: "GET",
            data: {"phone": $("input[name='phone']").val()},
            dataType: "json",
            success: function (data) {
                if (data) {
                    Toast('登录成功', 2000);
                    location.href = "doindex";
                } else {
                    Toast('登录失败,请联系管理员!', 2000);
                }
            },
        })
    } else {
        Toast('验证码不正确', 2000);
    }
}


//表单提交事件
$(".form2").submit(function () {

    var phone = $(".merphone").val()
    var pwd = $(".merpwd").val()
    if (phone == "") {
        layer.msg("手机号不能为空!")
        return false;
    }
    if (pwd == "") {
        layer.msg("密码不能为空!")
        return false;
    }

    if (phone != "" && pwd != "") {
        $.ajax({
            type: "POST",
            url: "loginphpw",
            data: $(".form2").serialize(),
            success: function (data) {
                if (data) {
                    layer.msg("修改成功!")
                    location.href = "doindex";
                } else {
                    layer.msg("账号或密码输入不正确!")
                }
            }, error: function (data) {
                layer.msg("操作异常!")
            }

        })
    }

    return false;
})
		
		
		
		
		